package org.budo.xml;

import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

/**
 * 对应一个Xml节点
 * 
 * @author lmw
 */
public class XmlNodeObject extends AbstractXmlObject {
    private Node node;

    public XmlNodeObject(Node node) {
        this.node = node;
    }

    public Node getNode() {
        return this.node;
    }

    @Override
    public String getChildNodeTextContentByName(String nodeName) {
        return this.getChildNodeByName(nodeName).getTextContent();
    }

    @Override
    public XmlObject getChildNodeByName(String nodeName) {
        return this.getChildNodeByName(this.getNode(), nodeName);
    }

    @Override
    public String getTextContent() {
        return this.getNode().getTextContent();
    }

    @Override
    public String getAttributeValue(String attributeName) {
        NamedNodeMap attributes = this.getNode().getAttributes();
        Node attributeNode = attributes.getNamedItem(attributeName);
        if (null == attributeNode) {
            return null;
        }

        return attributeNode.getNodeValue();
    }

    @Override
    public XmlObject[] getChildNodeArrayByName(String nodeName) {
        return this.getChildNodeArrayByName(this.getNode(), nodeName);
    }

    @Override
    public String toString() {
        return super.toString() + ", node=" + this.getNode();
    }
}